﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core
{
    public static partial class problem
    {
        public static dynamic getAutoPid()
        {
            var sql = new Sql.SqlDataContext();
            var pids = from p in sql.Problem
                     where p.pid > 1000
                     orderby p.pid
                     select p.pid;
            var first = pids.FirstOrDefault();
            if (first == default(int)) return new
                {
                    success = true,
                    pid = 1001
                };
            pids = pids.Skip(1);
            foreach (var p in pids)
            {
                if (p - first > 1) break;
                first = p;
            }
            return new
            {
                success = true,
                pid = first + 1
            };
        }
    }
}
